package cn.fighter3.utils;

import org.springframework.security.crypto.bcrypt.BCrypt;

public class TestUtil {

    public static void main(String[] args) {
        String password = "123456";
        // Hash a password for the first time
        String hashpw = BCrypt.hashpw(password, BCrypt.gensalt());

        // gensalt's log_rounds parameter determines the complexity
        // the work factor is 2**log_rounds, and the default is 10
        String hashpw2 = BCrypt.hashpw(password, BCrypt.gensalt(12));
        System.out.println("salt:" + BCrypt.gensalt());
        System.out.println("salt2:" + BCrypt.gensalt(12));
        System.out.println("hashpw:" + hashpw);
        System.out.println("hashpw2:" + hashpw2);

        String inputStr = "testPassword";
        // Check that an unencrypted password matches one that has
        // previously been hashed
        if (BCrypt.checkpw(inputStr, hashpw2)) {
            System.out.println("It matches");
        } else {
            System.out.println("It does not match");
        }
    }
}